package com.sf.net;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.sf.entity.Company;
import com.sf.entity.Login;

public class JsonUtil {

	public static Login getData(String json) {
		try {
			JSONArray ja = new JSONArray(json);
			JSONObject jb = ja.getJSONObject(0);
			Login login = new Login();
			login.setUseId(String.valueOf(jb.getInt("id")));
			login.setStoreid(jb.getString("storeid"));
			return login;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static List<Company> getComList(String json) {
		List<Company> list = new ArrayList<Company>();
		try {
			JSONArray ja = new JSONArray(json);
			for (int i = 0; i < ja.length(); i++) {
				JSONObject jb = ja.getJSONObject(i);
				Company com = new Company();
				com.setStoreId(jb.getString("id"));
				com.setScoreStartDate(jb.getString("ScoreStartDate"));
				com.setStoreName(jb.getString("StoreName"));
				list.add(com);
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
